from selenium import webdriver
import time

from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

options = webdriver.ChromeOptions()

options.page_load_strategy = "normal"  # 等待页面完全加载
# 创建浏览器驱动对象
driver = webdriver.Chrome(options=options)
url = r"E:/QQ缓存/A.html"
data = [
    {
        "id": "userA",
        "value": "╰(*°▽°*)╯"
    },
    {
        "id": "passwordA",
        "value": "小乔大王"
    },
    {
        "id": "telA",
        "value": "110"
    },
    {
        "id": "emailA",
        "value": "110@qq.com"
    }
]
driver.get(url)
for d in data:
    # 使用id定位输入用户名
    driver.find_element(by=By.ID, value=d.get("id")).send_keys(d.get("value"))

Select(driver.find_element(by=By.ID, value="selectA")).select_by_value("cq")
# 属性 name 定位
driver.find_element(By.NAME, "upfilea").send_keys(url)
# 标签定位
driver.find_element(By.TAG_NAME, "input").send_keys("admin")
# # 超链接定位
# driver.find_element(By.LINK_TEXT, "访问 新浪 网站").click()
# driver.find_element(By.LINK_TEXT, "体育").click()

# XPATH 定位
inputDom = driver.find_element(By.XPATH, "//input")
data={
    "是否显示":inputDom.is_displayed(),
    "是否启用":inputDom.is_enabled(),
    "是否被选定":inputDom.is_selected(),
    "位置和大小":inputDom.rect,
}
print(data)
# 元素属性
# driver.find_element(By.XPATH, "//[@type='password']").send_keys("XPATH属性定位")
# # 暂停3秒
input("按任意键关闭")
# # 关闭驱动对象
driver.quit()
print("结束")
